#!/bin/bash

if [ -n "$1" ] ; then
  data_date=$1
else
  data_date=`date -d "-1 days" +%F`
fi

ADS_LOG_LOAD_ODS_SQL="
LOAD DATA INPATH '/warehouse/ads_log/${data_date}'
OVERWRITE INTO TABLE jtp_ads_warehouse.ods_ads_log_inc PARTITION (dt='${data_date}');
"

ODS_ADS_INFO_FULL_SQL="
LOAD DATA INPATH '/warehouse/ads_basic/ads/${data_date}'
OVERWRITE INTO TABLE jtp_ads_warehouse.ods_ads_info_full PARTITION (dt ='${data_date}');
"

ODS_ADS_PLATFORM_FULL_SQL="
LOAD DATA INPATH '/warehouse/ads_basic/ads_platform/${data_date}'
OVERWRITE INTO TABLE jtp_ads_warehouse.ods_ads_platform_full PARTITION (dt ='${data_date}');
"

ODS_PLATFORM_INTO_FULL_SQL="
LOAD DATA INPATH '/warehouse/ads_basic/platform_info/${data_date}'
OVERWRITE INTO TABLE jtp_ads_warehouse.ods_platform_info_full PARTITION (dt ='${data_date}');
"

ODS_PRODUCT_INFO_FULL_SQL="
LOAD DATA INPATH '/warehouse/ads_basic/product/${data_date}'
OVERWRITE INTO TABLE jtp_ads_warehouse.ods_product_full PARTITION (dt ='${data_date}');
"

/opt/module/spark/bin/beeline -u jdbc:hive2://node101:10001 -n bwie -e "${ADS_LOG_LOAD_ODS_SQL}
${ODS_ADS_INFO_FULL_SQL}${ODS_ADS_PLATFORM_FULL_SQL}${ODS_PLATFORM_INTO_FULL_SQL}${ODS_PRODUCT_INFO_FULL_SQL}"